import org.stringtemplate.v4.STGroup;
import org.stringtemplate.v4.STGroupFile;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

public class LinkViz {

    STGroup templates;
    
    List<Link> links = new LinkedList<>();

    public static class Link {
        String from;
        String to;
        public Link(String from, String to) {this.from = from; this.to = to;}
    }
    
    public LinkViz(String stgPath) throws IOException{
        templates = new STGroupFile(stgPath);
    }
    
    public void addLink(String from, String to) {
        links.add(new Link(from, to));
    }

    @Override
    public String toString() {
        var fileST = templates.getInstanceOf("file");
        fileST.add("gname", "testgraph");
        for(var link : links) {
            var edgeST = templates.getInstanceOf("edge");
            edgeST.add("from", link.from);
            edgeST.add("to", link.to);
            fileST.add("edges", edgeST);
        }
        
        return fileST.render();
    }
}
